package game 
{
	import flash.display.*;
	import flash.events.MouseEvent;
	import windowsfla.MainMenuWindow;
	/**
	 * ...
	 * @author Goretskiy Alex
	 */
	public class MainMenu implements IWindow
	{
		//--------------------------------------------------------------------------
		//
		//  Variables
		//
		//--------------------------------------------------------------------------
		
		//----------------------------------
		//  Static variables
		//----------------------------------
		
		private static var _instance:MainMenu;
		
		//----------------------------------
		//  Protected variables
		//----------------------------------
		
		protected var _window:MovieClip;
		
		//--------------------------------------------------------------------------
		//
		//  Getters and setters
		//
		//--------------------------------------------------------------------------
		
		public function get window():MovieClip { return _window; }
		
		public static function get instance():MainMenu 
		{
			if ( !_instance )
			{
				_instance = new MainMenu();
			}
			
			return _instance;
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		//----------------------------------
		//  Constructor
		//----------------------------------
		
		public function MainMenu() 
		{
			
		}
		
		//----------------------------------
		//  Public methods
		//----------------------------------
		
		public function init( stage:Stage ):void
		{
			_window = new MainMenuWindow();
			stage.addChild( _window );
			
			const play_game:DisplayObject = Utils.getChildByNameDeep( _window, "play_game" );
			play_game.addEventListener( MouseEvent.CLICK, startGame );
		}
		
		//----------------------------------
		//  Events
		//----------------------------------
		
		private function startGame( e:MouseEvent ):void 
		{
			e.target.removeEventListener( MouseEvent.CLICK, startGame );
			
			Game.instance.init( _window.stage );
			
			if ( _window.parent )
			{
				_window.parent.removeChild( _window );
			}
		}
		
	}

}